package com.jukte.recipe;

import java.util.ArrayList;
import java.util.List;
import com.ewhat.recipes.R;
import com.jukte.recipe.adapters.ResourceGridAdapter;
import com.jukte.recipe.models.AboutResource;
import com.jukte.recipe.utils.AppUtility;
import android.net.Uri;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ResourceGridActivity extends BaseActivity {

	private Context con;
	private GridView resourceGrid;
	private ResourceGridAdapter adapter;
	private List<AboutResource> resources;
	private String[] urls={"http://1999dnvcoezxfueyy9h8odwqfs.hop.clickbank.net/?tid=APP","http://9dbeaspfi37teyf2lp0ftltz07.hop.clickbank.net/?tid=APP","http://www.guiltfreedesserts.net/hg/?a=zEmAbfe&p=3&tid=ma","http://ee6d4enbh2523v2lyxew9rcxe0.hop.clickbank.net/?tid=APP","http://48388qtdj53wepa5mgjg3gnkdi.hop.clickbank.net/?tid=APP","http://d18f9flfk321er7f-jjxihz8ep.hop.clickbank.net/?tid=APP",};
	private String[] texts={"Acid Alcaline Diet","Grain Free Solutions","Guilt Free Desserts","One Minute Cure","Cooking Quinoa","Sinfully Healthy Food",};
	private String[] imgPaths={"acidalkalinediet","grainfreesolutions","guiltfreedesserts","oneminutecure","cookingquinoa","sinfullyhealthyfood"};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_resource_grid);
		init();
		
		resourceGrid=(GridView)findViewById(R.id.grid);
		con=ResourceGridActivity.this;
		getData();
		adapter=new ResourceGridAdapter(ResourceGridActivity.this, 0, resources);
		resourceGrid.setAdapter(adapter);
		resourceGrid.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v,
				int position, long id) {
			   if(AppUtility.isInternetConnected(con))
			   {
				   
				   Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(resources.get(position).getUrl()));
				   startActivity(browserIntent);
			   }
			   else
			   {
				   Toast.makeText(con, "No Internet Connection!!", Toast.LENGTH_LONG).show();
			   }
			}
		});
	}

	private void getData() {
		// TODO Auto-generated method stub
		resources=new ArrayList<AboutResource>();
		for(int i=0;i<urls.length;i++)
		{
			AboutResource r=new AboutResource();
			r.setImagePath(imgPaths[i]);
			r.setText(texts[i]);
			r.setUrl(urls[i]);
			resources.add(r);
		}
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		super.init();
		tv_title.setText("Resources");
	}

}
